<div class="reports">
  <div class="content_middle">

    <div class="report_content_header">
      <div class="report_content_heading">
        <h1><%= t('views.reports.aged_accounts_receivable') %></h1>
      </div>

      <div class="content_header_data">
        <div class="header_data_left">
          <div class="header_data_detail">
            <ul>
              <li class="header_name "><%= @report.client_name %></li>
              <li class="header_duration"><%= @report.period %></li>
              <li class="header_description">
                <%= t('views.reports.aged_accounts_receivable_dtl') %>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <!-- content_header_data -->
    </div>
    <!-- report_content_header -->

    <%= render 'reports/report_partials/format_links'%>

    <div class="grid_table">
      <table cellpadding="0" cellspacing="0" class="table_listing aged_accounts_listing <%= I18n.locale %>">
        <colgroup>
          <col class="one"/>
          <col class="two"/>
          <col class="three"/>
          <col class="four"/>
          <col class="five"/>
          <col class="six"/>
        </colgroup>
        <thead>
        <tr>
          <th class="align_left"><%= t('views.clients.client_name') %></th>
          <th class="align_right"><%= t('views.reports.days_0_30') %></th>
          <th class="align_right {sorter:'thousands'}"><%= t('views.reports.days_31_60') %></th>
          <th class="align_right {sorter:'thousands'}"><%= t('views.reports.days_61_90') %></th>
          <th class="align_right {sorter:'thousands'}"><%= t('views.reports.days_above_90') %></th>
          <th class="align_right {sorter:'thousands'}"><%= t('views.reports.client_total_ar') %></th>
        </tr>
        </thead>
        <body>
        <% unless @report.report_data.blank? %>
            <% @report.report_data.group_by{|data| data["client_name"]}.values.each do |ages| %>
              <tr>
                <td class="align_left text-overflow-class" data-overflow-rows="2"  data-sort_val="<%= ages.first.attributes["client_name"] %>">
                  <%= ages.first.attributes["client_name"] %>
                </td>
                <td class="align_right" data-sort_val="<%= ages.sum{|aged| aged.attributes['zero_to_thirty'] }  %>">
                  <% ages.each do |aged| %>
                    <%= number_to_currency(aged.attributes["zero_to_thirty"],unit: aged.attributes['currency_code']) %>
                    <br>
                  <% end %>
                </td>
                <td class="align_right" data-sort_val="<%= ages.sum{|aged| aged.attributes['thirty_one_to_sixty'] } %>">
                  <% ages.each do |aged| %>
                    <%= number_to_currency(aged.attributes["thirty_one_to_sixty"],unit: aged.attributes['currency_code']) %>
                    <br>
                  <% end %>
                </td>
                <td class="align_right" data-sort_val="<%= ages.sum{|aged| aged.attributes['sixty_one_to_ninety'] } %>" >
                  <% ages.each do |aged| %>
                    <%= number_to_currency(aged.attributes["sixty_one_to_ninety"],unit: aged.attributes['currency_code']) %>
                    <br>
                  <% end %>
                </td>
                <td class="align_right" data-sort_val="<%= ages.sum{|aged| aged.attributes['ninety_one_and_above'] } %>" >
                  <% ages.each do |aged| %>
                    <%= number_to_currency(aged.attributes["ninety_one_and_above"],unit: aged.attributes['currency_code']) %>
                    <br>
                  <% end %>
                </td>
                <td class="align_right" data-sort_val="<%= ages.sum{|aged| aged.attributes["zero_to_thirty"] + aged.attributes["thirty_one_to_sixty"] + aged.attributes["sixty_one_to_ninety"] + aged.attributes["ninety_one_and_above"]} %>" >
                  <% ages.each do |aged| %>
                    <%= number_to_currency(aged.attributes["zero_to_thirty"] + aged.attributes["thirty_one_to_sixty"] + aged.attributes["sixty_one_to_ninety"] + aged.attributes["ninety_one_and_above"],unit: aged.attributes['currency_code']) %>
                    <br>
                  <% end %>
                </td>
              </tr>
            <% end %>
        <% else %>
            <tr>
              <td colspan="6" class="report_no_data"><%= t('views.reports.report_no_data') %></td>
            </tr>
        <% end %>
        <% unless @report.report_data.blank? %>
          <tfoot>
            <tr>
              <td class="align_left"><%= t("views.common.total") %></td>
              <td class="align_right">
                <% @report.report_total.each do |total| %>
                  <%= number_to_currency(total["zero_to_thirty"],unit:total["currency_code"]) %>
                  <br>
                <% end %>
              </td>
              <td class="align_right">
                <% @report.report_total.each do |total| %>
                  <%= number_to_currency(total["thirty_one_to_sixty"],unit:total["currency_code"]) %>
                  <br>
                <% end %>
              </td>
              <td class="align_right">
                <% @report.report_total.each do |total| %>
                  <%= number_to_currency(total["sixty_one_to_ninety"],unit:total["currency_code"]) %>
                  <br>
                <% end %>
              </td>
              <td class="align_right">
                <% @report.report_total.each do |total| %>
                  <%= number_to_currency(total["ninety_one_and_above"],unit:total["currency_code"]) %>
                  <br>
                <% end %>
              </td>
              <td class="align_right">
                <% @report.report_total.each do |total| %>
                  <%= number_to_currency(total["total_amount"],unit:total["currency_code"]) %>
                  <br>
                <% end %>
              </td>
            </tr>
          </tfoot>
        <% end %>
        </body>
      </table>
    </div>
    <!--grid_table-->

  </div>
  <!--content_middle-->

  <div class="content_bottom">
    <div class="report_footer">
      <!--</div>-->
      <div class="footer_note">
      </div>
    </div>
    <!-- report_footer -->
  </div>
  <!--content_bottom-->
</div><!--reports-->